package bb.lanxing.lib.devices.sprint.utils;

//import androidx.constraintlayout.core.motion.utils.TypedValues;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
//import com.easemob.util.EMPrivateConstant;
import bb.lanxing.lib.devices.api.ConnectionListener;
import bb.lanxing.lib.devices.api.SmartDevice;
import bb.lanxing.lib.devices.core.utils.DeviceHelper;
import kotlin.jvm.internal.Intrinsics;
import kotlin.text.StringsKt;
//import net.java.sip.communicator.impl.protocol.jabber.extensions.jingle.ParameterPacketExtension;
/* compiled from: XossDeviceConnectionWatcher.kt */

public final class XossDeviceConnectionWatcher implements DefaultLifecycleObserver {
    private final ConnectionListener connectStateListener;
    private final ConnectionListener connectionListener;
    private final String target;

    public interface ConnectionListener {
        void onConnected();

        void onConnecting();

        void onDisconnected();

        void onConnectionStateChanged(SmartDevice smartDevice, int i, int i2);

    }

//    @Override
//    public /* synthetic */ void onPause(LifecycleOwner lifecycleOwner) {
//        DefaultLifecycleObserver.CC.$default$onPause(this, lifecycleOwner);
//    }
//
//    @Override
//    public /* synthetic */ void onResume(LifecycleOwner lifecycleOwner) {
//        DefaultLifecycleObserver.CC.$default$onResume(this, lifecycleOwner);
//    }
//
//    @Override
//    public /* synthetic */ void onStart(LifecycleOwner lifecycleOwner) {
//        DefaultLifecycleObserver.CC.$default$onStart(this, lifecycleOwner);
//    }
//
//    @Override
//    public /* synthetic */ void onStop(LifecycleOwner lifecycleOwner) {
//        DefaultLifecycleObserver.CC.$default$onStop(this, lifecycleOwner);
//    }

    public XossDeviceConnectionWatcher(String str, ConnectionListener connectionListener) {
        Intrinsics.checkNotNullParameter(connectionListener, "connectionListener");
        this.target = str;
        this.connectionListener = connectionListener;
        this.connectStateListener = new ConnectionListener() {
            @Override
            public void onConnected() {

            }

            @Override
            public void onConnecting() {

            }

            @Override
            public void onDisconnected() {

            }

            @Override
            public final void onConnectionStateChanged(SmartDevice smartDevice, int i, int i2) {
                XossDeviceConnectionWatcher.connectStateListener(XossDeviceConnectionWatcher.this, smartDevice, i, i2);
            }
        };
    }

    public final ConnectionListener getConnectionListener() {
        return this.connectionListener;
    }

    public final String getTarget() {
        return this.target;
    }

    public final ConnectionListener getConnectStateListener() {
        return this.connectStateListener;
    }

    public static void connectStateListener(XossDeviceConnectionWatcher watcher, SmartDevice smartDevice, int i, int i2) {
        if (i == 1) {
            String address = smartDevice.getAddress();
            if (!watcher.isTarget(address)) {
                return;
            }
            watcher.connectionListener.onConnecting();
        } else if (i == 2) {
            String address2 = smartDevice.getAddress();
            if (!watcher.isTarget(address2)) {
                return;
            }
            watcher.connectionListener.onConnected();
        } else if (i == 4) {
            String address3 = smartDevice.getAddress();
            if (!watcher.isTarget(address3)) {
                return;
            }
            watcher.connectionListener.onDisconnected();
        }
    }

    public final boolean isTarget(String value) {
        String str;
        String obj = StringsKt.trim((CharSequence) value).toString();
        String str2 = this.target;
        if (str2 == null || (str = StringsKt.trim((CharSequence) str2).toString()) == null) {
            str = "";
        }
        return StringsKt.equals(obj, str, true);
    }

    @Override
    public void onCreate(LifecycleOwner owner) {
        DeviceHelper.registerConnectionStateListener((bb.lanxing.lib.devices.api.ConnectionListener) this.connectStateListener);
    }

    @Override
    public void onDestroy(LifecycleOwner owner) {
        DeviceHelper.unregisterConnectionStateListener((bb.lanxing.lib.devices.api.ConnectionListener) this.connectStateListener);
    }
}
